<template>
	<cxView display="flex" justifyContent="space-between" border="2rpx solid #ff8b48" alignItems="center"
		marginLeft="20" marginRight="20" borderRadius="100" background="white" :height="height" padding="10rpx">
		<cxView v-if="allowInput==false" margin-left="16" color="#999999" @confirm="click">{{placeholder}}</cxView>
		<cxField :placeholder="placeholder" @onInput="valueChanged" :value="searchValueComputer"
			v-else="allowInput==true" class="flexGrow"></cxField>
		<!-- <u-input v-model="searchValue" type="text"  placeholder="请输入商品名称" /> -->
		<cxView width="100" :showCircula="true" background="linear-gradient(to right bottom ,#f7d9a3, #ff8b48 )"
			display="flex" justifyContent="center" alignItems="center" @confirm="search">
			<cxImg src="search" color="white" width="60" height="60" size="40"></cxImg>
		</cxView>

	</cxView>
</template>

<script>
	export default {
		name: "bSearchBar",
		data() {
			return {
				value: '',
				name: ''

			};
		},

		props: {
			// 输入框的初始化内容
			keyword: {
				type: String,
				default: ''
			},
			allowInput: {
				type: Boolean,
				default: true
			},
			height: {
				tpye: [String, Number],
				default: '80'
			},
			placeholder: {
				type: String,
				default: '请输入'
			}

		},
		computed: {
			searchValueComputer: {
				get() {
					this.value = this.keyword;

					return this.value
				},
				set(v) {
					this.value = v
				}
			}

		},
		mounted() {

		},
		methods: {
			valueChanged(e) {
				this.value = e;
				this.$emit('valueChange', e);
				this.name = this.value;
			},
			search(e) {
				if (this.name.length === 0) {
					return
				}
				this.$emit('search', this.name);
				try {
					// 收起键盘
					uni.hideKeyboard();
				} catch (e) {}
			},
			click(e) {
				this.$emit("click");
			}
		}
	}
</script>

<style lang="scss">

</style>